{% extends "layout/base.html" %}
{% load staticfiles %}
{% block title %}登陆{% endblock  %}
{% block css %}
    <link rel="stylesheet" href="{% static 'css/account.css' %}">
    <style>
        .error-msg{
            color: red;
            position: absolute;
        }
    </style>
{% endblock %}
{% block content %}
<div class="account">
        <div class="title">扫  码  登  陆</div>
    <hr>
        <div class="">
            <img id="imageCode" src="{% url 'account:get_image' %}" alt="" class="img-thumbnail">
            <hr>
            <div class="row">
                <a  href="#" class="col-lg-offset-1">点击图片刷新</a>
                <a href="https://mp.weixin.qq.com/cgi-bin/registermidpage?action=index&lang=zh_CN&token=" class="col-lg-offset-3">没有微信公众号？点这里</a>
            </div>

        </div>
    </div>
{% endblock %}
{% block js %}
    <script>
    $(function () {
        checkLogin();
        $("#imageCode").click(function () {
            var oldSrc = $(this).attr("src");// 获取原来的地址
            $(this).attr("src",oldSrc+"?");
        })
    });

    // 后台检查扫码
    function checkLogin() {
        $.ajax({
            url:{% url 'account:check_login' %},
            type:"GET",
            success:function (res) {
                console.log(res);
                if (res.status == 0){
                    console.log("无人扫码")
                }else if (res.status == 4){
                    console.log("扫码成功，等待确认");
                    $('#imageCode').css("-webkit-filter","blur(10px)")

                }else if (res.status == 6){
                    console.log("等待用户输入密码")
                }else if (res.status == 1){
                    console.log("登陆成功");
                    getCookie();
                }
                checkLogin()
            }
        })
    };
    // 获取cookies
    function getCookie() {
        $.ajax({
            url:{% url 'account:get_token' %},
            type:"GET",
            success:function (res) {
                {##}
                location.href = res.data;
                // 重定向到某一个页面
            }
        })
    }
    </script>

{% endblock js %}